package io.adrainty.bolee.security.repository.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.adrainty.bolee.security.mapper.IClientMapper;
import io.adrainty.bolee.security.models.bo.ClientBO;
import io.adrainty.bolee.security.models.entity.ClientEntity;
import io.adrainty.bolee.security.repository.IClientRepository;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author AdRainty
 * @version V1.0.0
 * @since 2025/8/9 下午7:28
 */

@Repository
public class ClientRepositoryImpl implements IClientRepository {

    @Resource
    private IClientMapper clientMapper;

    @Override
    public List<ClientEntity> getClientList() {
        List<ClientBO> clientBOList = clientMapper.selectList(null);
        return BeanUtil.copyToList(clientBOList, ClientEntity.class);
    }

    @Override
    public ClientEntity getClientEntity(String clientId) {
        Wrapper<ClientBO> wrapper = Wrappers.lambdaQuery(ClientBO.class)
                .eq(ClientBO::getClientId, clientId);
        ClientBO selectOne = clientMapper.selectOne(wrapper);
        if (selectOne == null) return null;
        return BeanUtil.copyProperties(selectOne, ClientEntity.class);
    }
}
